<template>
	<el-form ref="form" :model="form" label-width="80px">
	  <el-form-item label="用户名">
	    <el-input v-model="form.username"></el-input>
	  </el-form-item>
	  <el-form-item label="密码">
	    <el-input v-model="form.password"></el-input>
	  </el-form-item>
	  
	  <el-form-item>
	    <el-button type="primary" @click="onSubmit">登陆</el-button>
	    <el-button>取消</el-button>
	  </el-form-item>
	</el-form>
</template>

<script>
	import axios from "axios"
	export default {
	    data() {
	      return {
	        form: {
				username:'',
				password:''
	        },
			token:''
	      }
	    },
	    methods: {
	      onSubmit() {
	        console.log('submit!');
			axios.post('http://localhost:2001/api-user/v1/user/login',this.form).then(res=>{
				if(res.data.code==1){
					alert("OK")
					
					this.token = res.data.data.token;
					
					localStorage.setItem("username",res.data.data.user.username);
					
					localStorage.setItem("token",this.token);
					console.log(this.token)
					
					this.$router.push({path:'/index'})
					
				}else{
					alert("登陆失败")
				}
			})
	      }
	    }
	  }
</script>

<style>
</style>